Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

150
Visualizações
PostgresSQL Insert error: duplicate key value violates unique constraint "todo_task_key"

I am trying to insert some values to my table called todo, i've Postico gui open, which I can see the table visually on my screen better. The insert query was successfully, base off the console.log, that states "Data insert successful", which it went off one time and ever since running again it's just been doing the "todo_task_key" error.

const express = require("express");

const app = express();
app.set("view engine", "ejs");

const { Client } = require("pg")
const client = new Client();
client.connect();

const dotenv = require("dotenv")
dotenv.config()

const credentials = {
    user: process.env.PGUSER,
    host: process.env.PGHOST,
    database: process.env.PGDATABASE,
    password: process.env.PGPASSWORD,
    port: process.env.PGPORT
}


async function registerPerson(person) {
    const query = `
        INSERT INTO todo (task, status)
        VALUES ('Clean Kitchen', 0)
        RETURNING id
         `;
    // const values = [person.task, person.status];
    // // return client.query(text, values);
    client.query(query, (err, res) => {
        if (err) {
            console.error(err);
            return;
        }
        console.log('Data insert successful');
        client.end();
    });
}


registerPerson();

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

A duplicate key error means that you have tried to insert a row with the same key value as some other row already indexed by the todo_task_key index.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda